import request from '@/utils/request';

const api = process.env.NODE_ENV === "production" ? "https://gitee.com/api/v5" : "/api"

/**
 * @description: 获取用户信息
 * @param {String} owner 用户名
 * @return: 
 */
export function user(owner) {
  return request({
    url: `${api}/users/${owner}`,
    method: 'get',
  });
}

/**
 * @description: 获取仓库下文件列表
 * @param {String} owner 用户名
 * @param {String} repo  仓库名
 * @return: 
 */
export function trees(owner,repo,data) {
  return request({
    url: `${api}/repos/${owner}/${repo}/git/trees/master`,
    method: 'get',
    params:data
  });
}

/**
 * @description: 上传图片到仓库
 * @param {String} owner 用户名
 * @param {String} repo  仓库名
 * @param {String} path  图片名
 * @param {object} data  {
 *  access_token:'',
 *  content:'',
 *  message:'',
 * }
 * @return: 
 */
export function updata(owner,repo,path,data) {
  return request({
    url: `${api}/repos/${owner}/${repo}/contents/${path}`,
    method: 'post',
    data
  });
}

/**
 * @description: 上传图片到仓库
 * @param {String} owner 用户名
 * @param {String} repo  仓库名
 * @param {String} path  图片名
 * @param {object} data  {
 *  access_token:'',
 *  sha:'',
 *  message:'',
 * }
 * @return: 
 */
export function del(owner,repo,path,data) {
  return request({
    url: `${api}/repos/${owner}/${repo}/contents/${path}`,
    method: 'delete',
    params:data
  });
}


/**
 * @description: 获取文件sha
 * @param {String} owner 用户名
 * @param {String} repo  仓库名
 * @param {String} path  图片名
 * @return: 
 */
export function getSha(owner,repo,path) {
  return request({
    url: `${api}/repos/${owner}/${repo}/contents/${path}`,
    method: 'get'
  });
}